package com.magic.item.mapper;

import com.magic.item.pojo.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * Created by zhuqin on 2021/1/4
 */
public interface CategoryMapper extends Mapper<Category>, SelectByIdListMapper<Category, Long> {
    @Select("select * from tb_category where id = #{pid}")
    List<Category> selectCategoryByPid(Long pid);
    @Update("update tb_category set is_parent = 1 where id = #{pid}")
    void updateCategoryIsParent(Long pid);
    @Update("update tb_category set name = #{name} where id = #{id}")
    void updateCategoryName(@Param("name")String name, @Param("id")Long id);
    @Delete("delete from tb_category where id = #{id}")
    void deleteCategory(Long id);
    @Select("select * from tb_category where parent_id = #{pid}")
    List<Category> selectCategoryById(Long pid);
    @Update("update tb_category set is_parent = 0 where id = #{pid}")
    void updateCategoryIsParents(Long pid);
}
